{% extends "base_generic.html" %}

{% block title %}Delete Author - Local Library{% endblock %}

{% block content %}
<div class="row justify-content-center">
  <div class="col-md-6">
    <div class="card border-danger">
      <div class="card-header bg-danger text-white">
        <h4 class="mb-0"><i class="bi bi-exclamation-triangle"></i> Confirm Delete</h4>
      </div>
      <div class="card-body">
        <div class="alert alert-warning">
          <strong>Warning!</strong> This action cannot be undone.
        </div>
        
        <p>Are you sure you want to delete the following author?</p>
        
        <div class="card">
          <div class="card-body">
            <h5 class="card-title">{{ author.first_name }} {{ author.last_name }}</h5>
            <p class="card-text">
              {% if author.date_of_birth %}
                <strong>Born:</strong> {{ author.date_of_birth }}<br>
              {% endif %}
              {% if author.date_of_death %}
                <strong>Died:</strong> {{ author.date_of_death }}<br>
              {% endif %}
              <strong>Books in Library:</strong> {{ author.book_set.count }}
            </p>
            
            {% if author.book_set.all %}
              <div class="alert alert-danger">
                <strong>Warning:</strong> This author has books in the library. 
                You cannot delete this author until all their books are removed or reassigned.
              </div>
              
              <h6>Books by this author:</h6>
              <ul class="list-group list-group-flush">
                {% for book in author.book_set.all %}
                  <li class="list-group-item">
                    <a href="{{ book.get_absolute_url }}">{{ book.title }}</a>
                  </li>
                {% endfor %}
              </ul>
            {% endif %}
          </div>
        </div>
        
        <div class="mt-3">
          {% if author.book_set.all %}
            <div class="d-flex justify-content-between">
              <a href="{{ author.get_absolute_url }}" class="btn btn-secondary">
                <i class="bi bi-arrow-left"></i> Back to Author
              </a>
              <button type="button" class="btn btn-danger" disabled>
                <i class="bi bi-trash"></i> Cannot Delete (Has Books)
              </button>
            </div>
          {% else %}
            <form method="post">
              {% csrf_token %}
              <div class="d-flex justify-content-between">
                <a href="{{ author.get_absolute_url }}" class="btn btn-secondary">
                  <i class="bi bi-arrow-left"></i> Cancel
                </a>
                <button type="submit" class="btn btn-danger">
                  <i class="bi bi-trash"></i> Delete Author
                </button>
              </div>
            </form>
          {% endif %}
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock %} 